package com.sch.wanandroid.ui.girls.info

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sch.wanandroid.entity.GirlInfoEntity
import com.sch.wanandroid.network.NetWorkManager
import kotlinx.coroutines.launch


/**
 * Created by Sch.
 * Date: 2020/12/16
 * description:
 */
class GirlInfoViewModel : ViewModel() {
    private val _grilInfo = MutableLiveData<GirlInfoEntity>()
    val grilInfoLiveData: LiveData<GirlInfoEntity> = _grilInfo
    private val _errorMsg = MutableLiveData<String?>()
    val errorMsg: LiveData<String?> = _errorMsg


    fun getGirlInfo(girlsId: String) {
        viewModelScope.launch {
            try {
                val result = NetWorkManager.apiService.getGirlInfo(girlsId)
                _grilInfo.value = result.data
            } catch (e: Exception) {
                _errorMsg.value = e.toString()
            }
        }
    }

    fun getRemark(it: String) {
        viewModelScope.launch {
            try {
                val result = NetWorkManager.apiService.getGirlRemark(it)
                if (result.status == 100) {
                    Log.e("test", result.data)

                } else {
                    _errorMsg.value = result.msg
                }

            } catch (e: Exception) {
                _errorMsg.value = e.toString()
            }
        }

    }
}